const message = {
  namespaced: true,
  state() {
    return {

      show: false,
      content: '',
      duration: '2000',
      timeoutId: 0,
    }
  },
  mutations: {
    setShow(state,flag) {
      state.show = flag;
    },
    setContent(state,content) {
      state.content = content;
    },
    setDuration(state,duration) {
      state.duration = duration;
    },
    setTimeoutId(state, timeoutId) {
      state.timeoutId = timeoutId;
    }
  },
  actions: {
    start(context, content) {
      clearTimeout(context.state.timeoutId);
      context.commit('setShow', true);
      context.commit('setContent', content);
      const timeoutId = setTimeout(() => {
        context.commit('setShow', false);
      },context.state.duration);
      context.commit('setTimeoutId', timeoutId);
    }
  }
}

export default message